/**
 * 活跃营业部管理初始化
 */
var Hybrank = {
    id: "HybrankTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Hybrank.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '营业部名称', field: 'gYybName', visible: true, align: 'center', valign: 'middle'},
            {title: '总买卖(万)', field: 'gJmMoney', visible: true, align: 'center', valign: 'middle'},
            {title: '上榜日', field: 'gTdate', visible: true, align: 'center', valign: 'middle'},
            {title: '上涨成功率', field: 'gUpRate1dc', visible: true, align: 'center', valign: 'middle'},
            {title: '操作个股', field: 'gSname', visible: true}
    ];
};

/**
 * 检查是否选中
 */
Hybrank.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Hybrank.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加活跃营业部
 */
Hybrank.openAddHybrank = function () {
    var index = layer.open({
        type: 2,
        title: '添加活跃营业部',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/hybrank/hybrank_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看活跃营业部详情
 */
Hybrank.openHybrankDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '活跃营业部详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/hybrank/hybrank_update/' + Hybrank.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除活跃营业部
 */
Hybrank.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/hybrank/delete", function (data) {
            Feng.success("删除成功!");
            Hybrank.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("hybrankId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询活跃营业部列表
 */
Hybrank.search = function () {
    var queryData = {};
    queryData['date'] = $("#date").val();
    queryData['name'] = $("#name").val();
    Hybrank.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Hybrank.initColumn();
    var table = new BSTable(Hybrank.id, "/hybrank/list", defaultColunms);
    table.setPaginationType("server");
    Hybrank.table = table.init();
});
